package mtm.ui.misc;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JLabel;
import javax.swing.border.LineBorder;

public class ColorLabel extends JLabel {
	
	public static ColorLabel[] JOB_COLOR_LABEL = new ColorLabel[] {
		new ColorLabel(Color.red),
		new ColorLabel(Color.orange),
		new ColorLabel(Color.blue),
		new ColorLabel(Color.green),
		new ColorLabel(Color.pink),
		new ColorLabel(Color.magenta),
		new ColorLabel(Color.yellow),
	}; 
	
	private int selectedRGB;
	
	private MouseClickedListener listener;
	
	
	/**
	 * Constructor
	 * @param color
	 */
	public ColorLabel(Color color) {
		super();
		setOpaque(true);
		setBackground(color);
		setText("                  ");
		
		// listener for mouse
		addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				selectedRGB = getBackground().getRGB();
				listener.onMouseClicked();
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
				setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			}
		});
	}
	
	
	/**
	 * Return RGB value of selected color label
	 * @return
	 */
	public int getRGB() {
		return selectedRGB;
	}
	
	
	/**
	 * Listener for mouse click event
	 * @param listener
	 */
	public void setMouseClickedListener(MouseClickedListener listener) {
		this.listener = listener;
	}
	
	
	/**
	 *	Interface for mouse click event 
	 */
	public interface MouseClickedListener {
		public void onMouseClicked();
	}
	
}
